#ifndef LOADMAP_H
#define LOADMAP_H


#include "QuadTree.h"
#include "Object.h"
//#include "Mario.h"

#include <map>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
//#include <utility>
  
//using namespace std;

//template<typename int, typename QNode*>
//std::map<int, QNode *> QTMAP;
//typedef std::map<std::string, std::string> TStrStrMap;
class Mario;
class LoadMap
{
private:
	LPDIRECT3DDEVICE9	d3ddv;
	LPDIRECT3DSURFACE9	backBuffer;
	LPD3DXSPRITE		spriteHandler;	// SpriteHandler to draw texture


	std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
	std::vector<std::string> split(const std::string &s, char delim);

	//TStrStrMap tMap;
	std::map<int, QNode*> qTree_map;

public:
	LoadMap(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer, LPD3DXSPRITE spriteHandler);

	//read file quad tree
	//list<QNode*> qNode_list;
	list<Object*> obj_list;
	int numScore;
	int numLife;
	int numCoin;
	//Mario* mario_save;

	int posX_first;		//vi tri mario ban dau
	int posY_first;
	int posX_last;		//vi tri mario khi load map tu map phu tro lai map chinh, vi tri cua pipe
	int posY_last;
	
	int mario_state;
	int mario_direction;
	int mario_isSmall;	//0: small, 1: big

	bool submapToMap;

	void loadFileObj(char* file_name);			//load file chua obj len list, sau nay add vao quadtree
	void loadFileToMap(char* file_name);		//load file quadtree, build lai thanh cay quadtree
	void deserialize(QuadTree *root);
	void build(QNode *n);

	void saveFileObj(char* file_name, list<Object*> obj_list);			//save cac obj xuong file, de load game
};

#endif